package org.example.controller;
import org.example.entity.StudentEntity;
import org.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;

    // 增加学生
    @PostMapping("/add")
    public boolean addStudent(@RequestBody StudentEntity studentEntity) {
        return studentService.addStudent(studentEntity);
    }

    // 删除学生
    @DeleteMapping("/{id}")
    public boolean deleteStudent(@PathVariable("id") Integer studentId) {
        return studentService.deleteStudent(studentId);
    }

    // 更新学生信息
    @PutMapping
    public boolean updateStudent(@RequestBody StudentEntity studentEntity) {
        return studentService.updateStudent(studentEntity);
    }

    // 获取学生信息
    @GetMapping("/{id}")
    public StudentEntity getStudent(@PathVariable("id") Integer studentId) {
        return studentService.getStudentById(studentId);
    }

    // 获取所有学生
    @GetMapping
    public List<StudentEntity> getAllStudents() {
        return studentService.getAllStudents();
    }

    // 登录
    @PostMapping("/login")
    public StudentEntity login(@RequestBody Map<String, String> StudentInfo) {
        String username = StudentInfo.get("username");
        String password = StudentInfo.get("password");
        return studentService.login(username, password);
    }


}
